<?php
/**
 * Created by PhpStorm.
 * User: xshaitt
 * Date: 2016/8/5
 * Time: 16:11
 */
namespace Home\Controller;

use Think\Controller;

class DynamicController extends VController
{
    public function reply()
    {
        //对动态回复
        $data = I('post.');
        $data['uid'] = $this->myUserData['id'];
        $data['username'] = $this->myUserData['username'];
        $data['zonedp'] = $this->myUserData['zonedp'];
        $data['ctime'] = time();
        $model = M('DynamicComment');
        $model->create();
        $result = $model->add($data);
        if ($result > 0) {
            $this->ajaxReturn(array('status' => 0, 'message' => '回复成功！','username'=>$this->myUserData['username'],'zonedp'=>$this->myUserData['zonedp'],'id'=>$result,'content'=>$data['content'],'ctime'=>date('Y-m-d H:i',$data['ctime'])));
        }
        $this->ajaxReturn(array('status' => 1, 'message' => '回复失败！'));
    }

    //删除动态
    public function delDynamic()
    {
        if (IS_AJAX) {
            $did = I('post.did');
            $model = M('Dynamic');
            $result = $model->where("uid='{$this->myUserData['id']}'")->find($did);
            if ($result == null) {
                $this->ajaxReturn(array('status' => 1, 'message' => '删除失败！'));
            } else {
                //删除一条动态只删除动态就是了，不需要删除原文与原谅的评论
                M('DynamicComment')->where("did='{$did}'")->delete();
                $result = $model->delete($did);
                if ($result > 0) {
                    $this->ajaxReturn(array('status' => 0, 'message' => '删除成功！'));
                }
            }
        } else {
            $this->ajaxReturn(array('status' => 1, 'message' => '非法数据来源！'));
        }
    }

    //删除动态的某一条评论
    public function delComment()
    {
        if (IS_AJAX) {
            $mid = I('post.mid');
            $model = M('DynamicComment');
            $result = $model->delete($mid);
            if ($result > 0) {
                $this->ajaxReturn(array('status' => 0, 'message' => '删除成功！'));
            } else {
                $this->ajaxReturn(array('status' => 1, 'message' => '删除失败！'));
            }

        } else {
            $this->ajaxReturn(array('status' => 1, 'message' => '非法数据来源！'));
        }
    }
}